package main

import (
	"fmt"
)

type Integer int

func (a Integer) add(b int) int {
	return int(a) + b
}

type Code int

const (
	SuccessCode   Code = 0
	UnvalidCode   Code = 4 //校验失败
	ServerErrCode Code = 9 //服务错误
)

var msgMap = map[Code](map[string]string){
	SuccessCode: map[string]string{
		"en": "Success",
		"zh": "请求成功",
	},
	UnvalidCode: map[string]string{
		"en": "unvalid",
		"zh": "未校验",
	},
	ServerErrCode: map[string]string{
		"en": "server error",
		"zh": "服务器错误",
	},
}

var i18n = "zh"

func (c Code) getMsg() string {
	// 可能会有更加响应码返回不同消息内容的要求，我们在这个函数里面去实现即可
	// 可能还会有国际化操作
	return msgMap[c][i18n]
}

func main() {
	var a Integer = 1
	fmt.Println(a.add(2))

	fmt.Printf("msg code %#v:%s\n", ServerErrCode, ServerErrCode.getMsg())
}
